#include <iostream>
#include <cmath>
#include <list>
#include <cppunit/CompilerOutputter.h>
#include <cppunit/extensions/TestFactoryRegistry.h>
#include <cppunit/ui/text/TestRunner.h>
#include <boost/numeric/mtl/mtl.hpp>
#include <CGAL/Random.h>

#include "fmm.h"
#include "backtracking.h"
#include "randompoint.h"
#include "sknn.h"
#include "gcvt.h"


GCVT::GCVT (Mesh & mesh, unsigned num_voronoi_cell)
{
	Random_points_mesh random_mesh (mesh);
	Mesh::Point random_sites;
	Mesh::FaceHandle random_sites_face_handle;
	for (int i = 0; i < num_voronoi_cell; ++i)
	{
		random_mesh.generate_point(random_sites, random_sites_face_handle);
		mesh.data(random_sites_face_handle).point_set.push_back(std::make_pair(random_sites, -1.0));
	}
}
	//Only return the one neighbor currently
void GCVT::adjust_position()
{
	static Random_points_mesh random_mesh (mesh);

	Mesh::Point random_point;
	Mesh::FaceHandle random_point_face;
	
	unsigned train_times = 100;
	for (int i = 0; i < train_times; ++i)
	{
		random_mesh.generate_point(random_point, random_point_face);
		std::vector<Point_info> neighbors; 
		sknn(mesh, random_point, random_point_face, 1, neighbors);
		//Draw Geodesics.
		//Backtracking<double>::draw_geodesics (mesh, neighbors[0].iter->first, );
	}
	//Generate an random point;
	//Find the nearest sites of point in geodesics metric;
	//Adjust its position on mesh;
	//		Get the path, compute the length//
	//		Read its weight//
	//		Compute the offset//
	//		Track the path with the offset//
	//		Set the new position of the point on the path//
	//			//Disconnect this point to the original face
	//			//Reconnect this point to the new face 
	//			//Adjust its weights;
}
void GCVT::k1_neighbor (const Mesh::Point & start_point, Mesh::Point & neighbor)
{
	//Do fast marching from start_point;
	//Foreach sites compute the value from start_point to this site
	//Choose the least one, set it to be the neighbor

}
void GCVT::geodesics(const Mesh::Point & site, const Mesh::FaceHandle fh, std::list<Mesh::Point> & path, std::vector<Mesh::FaceHandle> & face_record )
{
	//Preconditin: The geodesics field has been computed.
	//Draw the geodescis path backtracking to the start point.
	//Return the path.
}

